package com.atguigu.gmall.list.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class ThreadPoolExecutorConfig {

    @Bean
    public ThreadPoolExecutor threadPoolExecutor(){
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                12,//核心线程数， CPU密集型：数量+1    IO密集型：数量*2
                100,//最大线程数
                3L,//线程空闲时间
                TimeUnit.SECONDS,//存活时间的单位
                new ArrayBlockingQueue<>(3),//用于缓存任务阻塞队列
                Executors.defaultThreadFactory(),//指定创建线程的工厂
                new ThreadPoolExecutor.AbortPolicy()//默认拒绝策略，如果线程处理不来，直接抛出异常
        );
        return threadPoolExecutor;
    }
}
